using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using CrewCalculator.Models;
using Orchard.Indexing; 
namespace CrewCalculator {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			// Creating table CrewDataRecord
			SchemaBuilder.CreateTable(typeof(CrewCalculatorPartRecord).Name, table => table
				.ContentPartRecord()
                .Column("UserName", DbType.String, column => column.WithLength(100))
                .Column("Species", DbType.String)
                .Column("ShipCrew", DbType.Double)
                .Column("CurrentCrew", DbType.Double)
            )
            ;
            return 1;
        }

        public int UpdateFrom1()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(CrewCalculatorPart).Name,
              builder => builder.Attachable());
            return 2;
        }

        public int UpdateFrom2()
        {
            ContentDefinitionManager.AlterTypeDefinition("CrewCalculator", cfg => cfg
              .WithPart("CommonPart")
              .WithPart("RoutePart")
              .WithPart("CrewCalculatorPart")
              .WithPart("CommentsPart")
              .WithPart("TagsPart")
              .WithPart("LocalizationPart")
              .Creatable()
              .Indexed());
            return 3;
        }
    }
}